#include <STC15F2K60S2.H>



void Select_Latch(unsigned char Latch_Num)
{
    switch (Latch_Num)
    {
        case 4:  P2 &= 0x1F;  P2 |= 0x80;  break;
        case 5:  P2 &= 0x1F;  P2 |= 0xA0;  break;
        case 6:  P2 &= 0x1F;  P2 |= 0xC0;  break;
        case 7:  P2 &= 0x1F;  P2 |= 0xE0;  break;
    }
}

unsigned char Get_KeyNum()
{
    unsigned char Key_Temp = 0;
    
    if (P33 == 0) { Key_Temp = 4; }
    if (P32 == 0) { Key_Temp = 5; }
    if (P31 == 0) { Key_Temp = 6; }
    if (P30 == 0) { Key_Temp = 7; }
    
    return Key_Temp;
}

void main()
{
    unsigned char KeyNum = 0;
        
    P0 = 0xFF;
    Select_Latch(4);
    
    while (1)
    {
        KeyNum = Get_KeyNum();
        if (KeyNum == 4){  P03 = ~P03; Select_Latch(4);  }
        if (KeyNum == 5){  P04 = ~P04; Select_Latch(4);  }
        if (KeyNum == 6){  P05 = ~P05; Select_Latch(4);  }
        if (KeyNum == 7){  P06 = ~P06; Select_Latch(4);  }
    }
}


















    


